<!--
 * @FilePath     : /jquery/demo/200-2.html
 * @Description  : 全选和取消全选
 * @Date         : 2025-03-26 22:29:24
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-03-26 22:34:47
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
  </head>
  <body>
    <h2>全选和取消全选</h2>

    <ul>
      <li>
        <input type="checkbox" />
        某个复选框
      </li>
      <li>
        <input type="checkbox" />
        某个复选框
      </li>
      <li>
        <input type="checkbox" />
        某个复选框
      </li>
      <li>
        <input type="checkbox" />
        某个复选框
      </li>
    </ul>

    <hr />

    <button id="btn">全选</button>
    <br />
    <button id="btn1">取消全选</button>

    <script src="/library/jquery.min.js"></script>
    <script src="/common/common.js"></script>
    <script>
      // 自定义扩展方法
      $.fn.extend({
        // 添加全选
        allChecked: function () {
          $(this).prop('checked', true)
        },
        // 取消全选
        allCancelChecked: function () {
          $(this).prop('checked', false)
        },
      })

      // 全选
      $('#btn').click(function () {
        $('input:checkbox').allChecked()
      })

      // 取消全选
      $('#btn1').click(function () {
        $('input:checkbox').allCancelChecked()
      })
    </script>
  </body>
</html>
